<template>
  <div class="outBankEdit" @click.stop="aotuTab=false">
    <div class="dropdown">
      <jc-button
        :btn-arr="['reload', 'remove', 'pass', 'sub', 'push', 'option', 'save', 'list', !list.length && 'check']"
        :disab-arr="[isDisabled && 'save', 'using', 'copy', 'freeze', 'toExcel']"
        :fbillno="prodValue.fbillNo"
        :list="'/saleRetuenList'"
        @refresh="queryTSalOrderNtry"
        @save="insert"
        @submit="insert(1)"
        @noSubmit="submit(2)"
        @audit="audit(1)"
        @noAudit="audit(2)"
        @forbidden="forbidden(1)"
        @startUsing="forbidden(2)"
        @cancellation="cancellation(1)"
        @NoCalncellation="cancellation(2)"
        @del="delPublic"
        @handleCom1="handleCom(1)"
        @handleCom2="handleCom(2)"
        @check="check('up')"
        @check1="check('down')"
        @pushDown="pushDown"
      />
    </div>
    <el-tabs v-model="activeName" class="tabs" @tab-click="handleClick">
      <el-tab-pane :label="$t('market.info')" name="first">
        <el-form ref="purchaseRef" :model="prodValue" label-width="100px" size="mini">
          <el-form-item :label="$t('market.state')" prop="fdocumentStatus">
            <el-tag :type="prodValue.stateColor">{{ prodValue.fdocumentStatus }}</el-tag>
          </el-form-item>
          <el-form-item :label="$t('market.billType')">
            <el-input
              v-model.trim="prodValue.fbilltype"
              size="mini"
              disabled
            />
          </el-form-item>
          <el-form-item :label="$t('market.billNo')">
            <el-input v-model="prodValue.fbillNo" disabled size="mini" />
          </el-form-item>
          <el-form-item :label="$t('market.fdate')" prop="fdate">
            <el-date-picker
              v-model="prodValue.fdate"
              type="date"
              value-format="yyyy-MM-dd"
              size="mini"
              :disabled="isDisabled"
              :placeholder="$t('market.checkDate')"
              style="width: 163px"
            />
          </el-form-item>
          <el-form-item :label="$t('market.cust')" prop="fcustomerId">
            <el-input v-model.trim="prodValue.fcustomer" size="mini" disabled>
              <i
                slot="suffix"
                class="el-input__icon el-icon-search"
                @click="clientVisiblit=true"
              />
            </el-input>
          </el-form-item>
          <el-form-item v-if="false" :label="$t('market.headDelivery')" prop="fheadDeliveryWay">
            <el-input v-model.trim="prodValue.fheadDeliveryWayName" size="mini" :disabled="isDisabled">
              <i
                slot="suffix"
                class="el-input__icon el-icon-search"
                @click="deliveVisiblit=true"
              />
            </el-input>
          </el-form-item>
          <el-form-item :label="$t('market.stocker')" prop="fstockerId">
            <el-autocomplete
              v-model.trim="prodValue.fstocker"
              highlight-first-item
              popper-class="my-autocomplete"
              :fetch-suggestions="querySearch11"
              size="mini"
              :disabled="isDisabled"
              @focus="queryStocker"
              @select="stockerData"
            >
              <i
                slot="suffix"
                class="el-input__icon el-icon-search"
                @click="openStocker=true"
              />
              <template slot-scope="{ item }">
                <div class="name">{{ item.fuserName }}</div>
              </template>
            </el-autocomplete>
          </el-form-item>
          <el-form-item :label="$t('market.saler')">
            <el-input v-model.trim="prodValue.fsalesman" size="mini" disabled />
          </el-form-item>
          <el-form-item :label="$t('market.paeztext3')">
            <el-input v-model.trim="prodValue.fpaeztext1" size="mini" :disabled="isDisabled" />
          </el-form-item>
          <el-form-item :label="$t('market.paeztext4')">
            <el-input v-model.trim="prodValue.fpaeztext2" size="mini" :disabled="isDisabled" />
          </el-form-item>
          <el-form-item label="s/o号">
            <el-input v-model.trim="prodValue.fpaeztext3" size="mini" :disabled="isDisabled" />
          </el-form-item>
          <!--          <el-form-item label="销售组织">-->
          <!--            <el-input v-model.trim="prodValue.fsaleorg" disabled />-->
          <!--          </el-form-item>-->
        </el-form>
        <div style="margin-bottom: 5px;margin-top: 10px;">
          <el-button size="mini" @click="newLine">{{ $t('btn.newHang') }}<!--新增行--></el-button>
          <el-button size="mini" @click="delHang">{{ $t('btn.delHang') }}<!--删除行--></el-button>
        </div>
        <!--明细表格-->
        <div>
          <jc-table
            :table-data="saleDetails"
            :table-header="tableHeader"
            :table-height="tableHeight"
            :get-summaries="getSummaries"
            show-summary
            @rowClick="rowClick"
          >
            <!--  物料编码-->
            <template v-slot:billSlot="col">
              <el-input
                v-model.trim="col.scope.row.fnumber"
                placeholder="请选择物料"
                size="mini"
                :disabled="isDisabled"
                @input="getAtuo(col.scope.$index, col.scope.row.fnumber)"
              >
                <i
                  slot="prefix"
                  class="iconfont icon-jin-rud-ao-bo"
                  @click="sonJumpMateriel(col.scope.row.fnumber)"
                />
                <i
                  slot="suffix"
                  class="el-input__icon el-icon-search"
                  @click="materia(col.scope.$index)"
                />
              </el-input>
              <div v-if="aotuTab && indexSelf === col.scope.$index" :class="indexSelf<7 ? 'tabPosit': 'tabPosit1'">
                <number-code :fnumber="fnumber" @material="materialData" />
              </div>
            </template>
            <!--实发数量-->
            <template v-slot:tagSlot="col">
              <el-input-number
                v-model="col.scope.row.frealqty"
                :min="0"
                :disabled="isDisabled"
                size="mini"
              />
            </template>
            <!--应发数量-->
            <template v-slot:btnState="col">
              <el-input-number
                v-model="col.scope.row.fmustqty"
                :min="0"
                :disabled="isDisabled"
                size="mini"
              />
            </template>
            <!--仓库-->
            <template v-slot:btnStates="col">
              <el-input
                v-model="col.scope.row.fstock"
                :min="0"
                :disabled="isDisabled"
                size="mini"
              >
                <i
                  slot="suffix"
                  class="el-input__icon el-icon-search"
                  @click="handleCK(col.scope.$index)"
                />
              </el-input>
            </template>
            <!--备注-->
            <template v-slot:text1Slot="col">
              <el-input
                v-model="col.scope.row.fnote"
                size="mini"
                :disabled="isDisabled"
              />
            </template>
            <!--操作-->
            <template v-slot:operaSlot="clo">
              <el-button type="danger" size="mini" :disabled="isDisabled" @click="handleDelete(clo.scope.$index)">
                {{ $t('shop.delete') }}
              </el-button>
            </template>
          </jc-table>
        </div>
      </el-tab-pane>
      <el-tab-pane :label="$t('market.fince')" name="two">
        <el-form ref="purchaseRef" :model="prodValue" label-width="100px" size="mini">
          <!--          <el-form-item label="结算组织">-->
          <!--            <el-input v-model.trim="prodValue.fsettleorg" disabled />-->
          <!--          </el-form-item>-->
          <el-form-item :label="$t('market.settleCurr')" prop="fsettlecurrId">
            <el-input v-model.trim="prodValue.fsettlecurr" size="mini" disabled>
              <i
                slot="suffix"
                class="el-input__icon el-icon-search"
                @click="currencyVisiblit=true"
              />
            </el-input>
          </el-form-item>
          <el-form-item :label="$t('market.settleType')" prop="fsettletypeid">
            <el-input v-model.trim="prodValue.fsettleType" size="mini" disabled>
              <i
                slot="suffix"
                class="el-input__icon el-icon-search"
                @click="isSettlement=true"
              />
            </el-input>
          </el-form-item>
          <el-form-item :label="$t('market.recCondition')" prop="freceiptconditionId">
            <el-input v-model.trim="prodValue.freceiptcondition" size="mini" disabled>
              <i
                slot="suffix"
                class="el-input__icon el-icon-search"
                @click="gatheringVisiblit=true"
              />
            </el-input>
          </el-form-item>
          <el-form-item :label="$t('market.exchangeType')">
            <el-input v-model="prodValue.fexchangetype" disabled size="mini" />
          </el-form-item>
          <el-form-item :label="$t('market.localCurr')">
            <el-input v-model="prodValue.flocalcurr" size="mini" disabled />
          </el-form-item>
          <el-form-item :label="$t('market.exchangeRate')">
            <el-input v-model="prodValue.fexchangerate" disabled size="mini" />
          </el-form-item>
          <el-form-item :label="$t('market.billtaxamount')">
            <el-input v-model="prodValue.fbilltaxamount" disabled />
          </el-form-item>
          <el-form-item :label="$t('market.billamount')">
            <el-input v-model="prodValue.fbillamount" disabled />
          </el-form-item>
          <el-form-item :label="$t('market.billallamount')">
            <el-input v-model="prodValue.fbillallamount" disabled />
          </el-form-item>
          <el-form-item :label="$t('market.billtaxamount_lc')">
            <el-input v-model="prodValue.fbilltaxamount_lc" disabled />
          </el-form-item>
          <el-form-item :label="$t('market.billamount_lc')">
            <el-input v-model="prodValue.fbillamount_lc" disabled />
          </el-form-item>
          <el-form-item :label="$t('market.billallamount_lc')">
            <el-input v-model="prodValue.fbillallamount_lc" disabled />
          </el-form-item>
        </el-form>
      </el-tab-pane>
      <el-tab-pane :label="$t('market.other')" name="log">
        <jc-marker
          ref="log"
          :fnumber="prodValue.fbillNo"
          other-height="68vh"
          :other-url-object="otherUrlObject"
        />
      </el-tab-pane>
    </el-tabs>
    <el-dialog
      v-dialogDrag
      :title="$t('market.checkBill')"
      model
      :visible.sync="isdanjuDialog"
      :close-on-click-modal="false"
      width="600px"
      center
      append-to-body
    >
      <div style="text-align: center;height: 100px;line-height: 100px">
        <el-radio-group v-model="orderLX" @change="orderWat">
          <el-radio v-for="item in receipts" :key="item" :label="item">
            {{ item }}
          </el-radio>
        </el-radio-group>
      </div>
      <hr>
      <div style="text-align: center;">
        {{ $t('market.rule') }}
        <el-input v-model="convert" size="mini" disabled style="width: 178px;margin-bottom: 5px;" />
        <br>
        {{ $t('market.billType') }}
        <el-select
          v-model.trim="fbillTypeId"
          size="mini"
          filterable
        >
          <el-option
            v-for="(item, index) in billTypeData"
            :key="index"
            :label="item.fname"
            :value="item.fid"
          />
        </el-select>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button size="mini" @click="isdanjuDialog = false">{{ $t('btn.cancel') }}</el-button>
        <el-button size="mini" type="primary" @click="pushDownOrder()">
          {{ $t('btn.confirm') }}
        </el-button>
      </span>
    </el-dialog>
    <!--结算币别列表-->
    <currency v-if="currencyVisiblit" @currency="currencyData" />
    <!--收款条件列表-->
    <gathering v-if="gatheringVisiblit" @gathering="gatheringData" />
    <!--客户列表-->
    <client v-if="clientVisiblit" @client="clientData" />
    <!--    物料弹窗-->
    <material v-if="isMateria" @material="materialData" />
    <!--结算方式弹窗-->
    <settlement v-if="isSettlement" @settlement="settlementData" />
    <!--交货方式列表-->
    <deliver v-if="deliveVisiblit" @delive="deliveData" />
    <!--    仓管员-->
    <stocker v-if="openStocker" @stocker="stockerData" />
    <!-- 仓库 -->
    <selectCK v-if="seleceVisiblit" @client="selectData" />
    <upDown v-if="upDownVis" :msg="cha" :fentryid="fentryData" @client="upDownVis=false" />
  </div>
</template>
<script>
import jumpMateriel from '@/components/JumpMateriel'
import mixinsImg from '@/views/market/marketManage/createMarkerOrder/components/mixinsImg'
import { querySalerRate, queryViewItem } from '@/api/marketManage/marketOrder'
import { toMxAmina } from '@/components/ToMxamineState'
import {
  querySalRetDetails, salRetAudit,
  salRetAuSubmit, salRetSubmit, salRetUnAudit,
  updateRet, salRetDelete, salRetClose, salRetUnClose, cancelsalRet, unCancelsalRet, returnPushToReceivable
} from '@/api/marketManage/deliveryRelease'
import operability from '@/mixin/Operability'
import autocomplete from '@/views/market/marketManage/createMarkerOrder/components/autocomplete'
import jcMarker from '@/components/marker'
import jcButton from '@/components/Button'

export default {
  name: 'EditSaleReturn',
  components: {
    currency: () => import('@/views/market/marketManage/createMarkerOrder/components/currency'),
    jcMarker,
    upDown: () => import('@/components/upDown'),
    gathering: () => import('@/views/market/marketManage/createMarkerOrder/components/gathering'),
    material: () => import('@/views/market/marketManage/createMarkerOrder/components/material'),
    settlement: () => import('@/views/purchasing/purchaseOrder/marketPushDown/components/settlement'),
    deliver: () => import('@/views/market/marketManage/createMarkerOrder/components/deliver'),
    client: () => import('@/views/market/marketManage/createMarkerOrder/components/client'),
    stocker: () => import('@/views/purchasing/putStorage/editStorage/component/stocker'),
    numberCode: () => import('@/components/NumberCode'),
    jcButton,
    selectCK: () => import('@/views/production/collect/components/seleceCK')
  },
  mixins: [jumpMateriel, mixinsImg, autocomplete, operability],
  props: {
    fbillNo: {
      type: String,
      default: ''
    },
    list: {
      type: Array,
      default: function() {
        return []
      }
    }
  },
  data() {
    return {
      isdanjuDialog: false,
      orderLX: this.$t('menu.receivable'),
      receipts: [this.$t('menu.receivable')], // 生产'采购退库单''应付单'
      fbillTypeId: 178,
      convert: this.$t('market.cgrkztk'),
      billTypeData: [], // 采购订单单据
      fentryData: [],
      upDownVis: false,
      cha: '',
      activeName: 'first', // 基本信息
      activeName1: 'first', // 明细信息
      targerName: 'outBank',
      seleceVisiblit: false, // 仓库
      currencyVisiblit: false, // 结算币别弹窗
      gatheringVisiblit: false, // 收款条件弹窗
      isMateria: false, // 物料弹窗
      isSettlement: false, // 结算方式
      isPayment: false, // 付款条件
      openSalesDepartment: false, // 销售部门
      clientVisiblit: false, // 客户
      deliveVisiblit: false, // 交货方式
      openStocker: false, // 仓管员
      billtypes: [], // 单据类型
      prodValue: {}, // 表单数据
      tableHeight: '46vh',
      indexSelf: 0,
      isDisabled: false,
      otherUrlObject: {},
      saleDetails: [],
      tableHeader: [
        { label: this.$t('shop.numIndex'), prop: 'fseq', width: '80' },
        { label: this.$t('market.frowType'), prop: 'frowtypename' },
        { label: this.$t('market.fmaterial'), type: 'bill', prop: 'fnumber', width: '160px' },
        { label: this.$t('shop.fname2'), prop: 'fname' },
        { label: this.$t('market.fmodel'), prop: 'fmodel', minWidth: '100px' },
        { label: this.$t('shop.fspecificaTion'), prop: 'fspecificaTion', minWidth: '120px' },
        { label: this.$t('market.fdescripTion'), prop: 'fdescripTion', minWidth: '200px' },
        { label: this.$t('market.stockUnit'), prop: 'funit', minWidth: '100px' },
        { label: this.$t('market.mustqty'), type: 'state', prop: 'fmustqty', minWidth: '90px' },
        { label: this.$t('market.realqty'), type: 'tag', prop: 'frealQty', minWidth: '90px' },
        { label: this.$t('market.fprice'), prop: 'fprice', width: '80' },
        { label: this.$t('market.ftaxPrice'), prop: 'ftaxprice', width: '80' },
        { label: this.$t('market.billamount'), prop: 'famount', width: '80' },
        { label: this.$t('market.billallamount'), prop: 'fallamount', width: '80' },
        { label: this.$t('market.ftaxRate'), prop: 'ftaxrate', width: '80' },
        { label: this.$t('market.billtaxamount'), prop: 'ftaxamount', width: '80' },
        { label: this.$t('market.stock'), type: 'states', prop: 'fstock', minWidth: '130px' },
        { label: this.$t('market.paezText1'), prop: 'fpaeztext', width: '120px' },
        { label: this.$t('market.note'), type: 'text1', prop: 'fnote', minWidth: '200px' },
        // { label: '发货组织', prop: 'fstockorg' },
        // { label: '货主', prop: 'fowner' },
        { label: this.$t('market.handle'), type: 'operate', width: '100px' }
      ],
      aotuTab: false,
      fnumber: ''
    }
  },
  watch: {
    fbillNo() {
      if (this.fbillNo) {
        this.queryTSalOrderNtry()
        this.queryBillType() // 单据类型
      }
    }
  },
  created() {
    if (this.$route.params.id) {
      this.queryTSalOrderNtry() // 获取订单列表数据
      this.queryBillType() // 单据类型
    }
    this.tableHeight = window.innerWidth > 1440 ? 'calc(100vh - 270px)' : '67vh'
  },
  methods: {
    getAtuo(index, fnumber) {
      this.indexSelf = index
      this.aotuTab = true
      var vm = this
      clearTimeout(vm.timer) // 清除未执行的代码，重置回初始化状态
      vm.timer = setTimeout(() => {
        this.fnumber = fnumber
      }, 600)
    },
    // 修改发货通知单
    async insert(ev) {
      const DATA = this.prodValue
      this.prodValue.details = this.saleDetails
      await updateRet(DATA).then(res => {
        if (res.code === 0) {
          ev === 1 ? this.submit(1) : this.queryTSalOrderNtry()
          if (this.fbillNo) {
            this.$emit('editOut', this.fbillNo)
          }
          this.$message({ showClose: true, message: res.message, type: 'success' })
        } else {
          this.$confirm(res.message, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'error'
          })
        }
      })
    },
    // 获取订单列表数据
    async queryTSalOrderNtry() {
      const id = this.$route.params.id || this.fbillNo
      const DATA = { fid: id }
      const { data: RES } = await querySalRetDetails(DATA)
      this.prodValue = toMxAmina(RES)
      this.otherUrlObject = RES
      this.saleDetails = RES.details
      this.isDisabled = this.prodValue.fdocumentStatus === this.$t('market.state1') || this.prodValue.fdocumentStatus === this.$t('market.state2')
    },
    // 单据类型
    async queryBillType() {
      const { data: RES } = await queryViewItem({ viewName: 'SX_OUTSTOCK' })
      this.billtypes = RES.list
    },
    // 获取结算币别数据(子传父)
    currencyData(item) {
      if (item.fsettleCurrId) {
        this.prodValue.fsettlecurr = item.fsettleCurrIdName
        this.prodValue.fsettlecurrId = item.fsettleCurrId
        this.currencyVisiblit = item.isCurrencyDialog
        // 获取汇率
        this.querySalerRate()
      } else {
        this.currencyVisiblit = item.isCurrencyDialog
      }
    },
    // 仓管员
    stockerData(item) {
      if (item.fuserId) {
        this.prodValue.fstockerId = item.fuserId
        this.prodValue.fstocker = item.fuserName
      }
      this.openStocker = false
    },
    // 收款条件列表
    gatheringData(item) {
      if (item.frecConditionId) {
        this.prodValue.freceiptcondition = item.frecConditionIdName
        this.prodValue.freceiptcondiTionId = item.frecConditionId
        this.gatheringVisiblit = false
      } else {
        this.gatheringVisiblit = false
      }
    },
    // 查询汇率
    async querySalerRate() {
      const DATA = {
        fexchangeTypeId: this.prodValue.fexchangeTypeId,
        fsettleCurrId: this.prodValue.fsettlecurrId,
        flocalCurrId: this.prodValue.flocalcurrId
      }
      const { data: RES, code, message } = await querySalerRate(DATA)
      if (code === 0) {
        this.prodValue.fexchangeRate = Number(RES.fexchangeRate)
      } else {
        this.prodValue.fexchangeRate = 0
        this.$confirm(message, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'error'
        })
      }
    },
    // 仓库
    handleCK(index) {
      this.indexSelf = index
      this.seleceVisiblit = true
    },
    // 获取仓库数据
    selectData(ev) {
      if (ev.ckid || ev.fstockId) {
        const item = this.saleDetails[this.indexSelf]
        item.fstockid = ev.ckid || ev.fstockId
        item.fstock = ev.ck || ev.fname
      }
      this.seleceVisiblit = false
    },
    // 打开物料弹窗
    materia(index) {
      this.isMateria = true
      this.indexSelf = index
    },
    // 获取物料
    materialData(ev) {
      if (ev.fnumber) {
        const item = this.saleDetails[this.indexSelf]
        item.fmodel = ev.fmodel
        item.fnumber = ev.fnumber
        item.fmaterialId = ev.fmaterialId
        item.fspecificaTion = ev.fspecificaTion
        item.fdescripTion = ev.fdescripTion
        item.funit = ev.funitName
        item.fmustQty = 0
        item.fstockId = 0
      }
      this.isMateria = false
    },
    // 结算方式
    settlementData(ev) {
      if (ev.fsettleTypeId) {
        this.prodValue.fsettleType = ev.fsettleType
        this.prodValue.fsettletypeid = ev.fsettleTypeId
      }
      this.isSettlement = false
    },
    // 付款条件
    paymentData(ev) {
      if (ev.fid) {
        this.prodValue.fpaycondiTion = ev.fname
        this.prodValue.fpaycondiTionId = ev.fid
      }
      this.isPayment = false
    },
    // 获取交货方式数据(子传父)
    deliveData(item) {
      if (item.fdataValue) {
        this.prodValue.fheadDeliveryWayName = item.fdataValue
        this.prodValue.fheadDeliveryWay = item.fheadDeliveryWay
        this.deliveVisiblit = false
      } else {
        // 点击关闭按钮
        this.deliveVisiblit = false
      }
    },
    // 获取客户数据(子传父)
    clientData(item) {
      if (item.fcustId) {
        this.prodValue.fcustomerId = item.fcustId
        this.prodValue.fcustomer = item.fname
        this.clientVisiblit = item.isclientlDialog
      } else {
        // 没传值，点击关闭按钮
        this.clientVisiblit = item.isclientlDialog
      }
    },
    handleDelete(index) {
      this.saleDetails.splice(index, 1)
    },
    // 公共函数
    toExamineFun(api) {
      const DATA = { Numbers: [this.prodValue.fbillNo] }
      api(DATA).then(res => {
        if (res.code !== 0) {
          this.$confirm(res.message, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'error'
          })
          return
        }
        this.innerHTM = ''
        res.data.forEach(res => {
          this.innerHTM += '<div>' + res + '</div>'
        })
        this.$notify.warning({
          title: '提示',
          message: this.innerHTM,
          duration: 3000, offset: 50,
          dangerouslyUseHTMLString: true
        })
        this.queryTSalOrderNtry()
      })
    },
    // 提交
    async submit(ev) {
      const api = ev === 1 ? salRetSubmit : salRetAuSubmit
      this.toExamineFun(api)
    },
    // 审核
    async audit(ev) {
      const api = ev === 1 ? salRetAudit : salRetUnAudit
      this.toExamineFun(api)
    },
    // 关闭
    async forbidden(ev) {
      const api = ev === 1 ? salRetClose : salRetUnClose
      this.toExamineFun(api)
    },
    // 作废
    async cancellation(ev) {
      const api = ev === 1 ? cancelsalRet : unCancelsalRet
      this.toExamineFun(api)
    },
    // 删除
    delPublic() {
      this.$confirm('此操作将永久删除该订单, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        const DATA = { Numbers: [this.prodValue.fbillNo] }
        salRetDelete(DATA).then(res => {
          if (res.code !== 0) {
            this.$confirm(res.message, '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'error'
            })
            return
          }
          // 关闭当前页面
          this.$store.dispatch('tagsView/guanbi', this.$route)
          this.$router.replace({ path: '/saleRetuenList' })
        })
      })
    },
    check(ev) {
      this.fentryData = []
      this.saleDetails.forEach(res => {
        this.fentryData.push(res.fentryId)
      })
      this.cha = ev
      this.upDownVis = true
    },
    // 套打
    handleCom(ev) {
      if (ev === 1) { // 通用
        this.$router.push({ path: `/saleRetuenTong/${this.prodValue.fbillNo}` })
      } else { // 连续
        this.$router.push({ path: `/saleRetuenLian/${this.prodValue.fbillNo}` })
      }
    },
    // 点击tabs
    handleClick(tab) {
      if (tab.name === 'log') {
        this.$refs.log.otherlog()
      }
    },
    // 新增行
    newLine() {
      this.saleDetails.push({
        fqty: 0,
        fmodel: '',
        fpaezText1: '',
        unitName: '',
        fmaterialId: 0,
        fspecificaTion: '',
        funitId: 0,
        fstockQty: 0,
        fprice: 0,
        ftaxPrice: 0,
        ftaxRate: 0,
        fdescripTion: '',
        fdeliveryDate: '',
        fnumber: '',
        fentryId: 0,
        fstockUnitId: 0,
        fstockPlace: '',
        pbdDetails: []
      })
    },
    // 单击行
    rowClick(row) {
      this.indexSelf = row.index
    },
    // 删除行
    delHang() {
      this.saleDetails.splice(this.indexSelf, 1)
    },
    // 下推采购订单
    pushDown() {
      this.isdanjuDialog = true
      this.orderLX = this.$t('menu.receivable')
      this.orderWat(this.$t('menu.receivable'))
    },
    orderWat(ev) {
      if (ev === this.$t('menu.receivable')) {
        this.purpoorder('SX_FRECEIVABLE_BILLTYPE')
        this.convert = this.$t('market.xsthzys')
        this.fbillTypeId = 1262
      }
    },
    // 采购退库单单据
    async purpoorder(ev) {
      const { data: RES } = await queryViewItem({ viewName: ev })
      this.billTypeData = RES.list
    },
    // 下推采购退库单
    pushDownOrder() {
      this.fentryData = []
      this.saleDetails.forEach(res => {
        this.fentryData.push(res.fentryId)
      })
      const DATA = {
        SoucrceIds: [this.prodValue.fid],
        EntryIds: this.fentryData,
        fbillTypeId: this.fbillTypeId
      }
      if (this.orderLX === this.$t('menu.receivable')) {
        returnPushToReceivable(DATA).then(res => {
          if (res.code === 0) {
            this.$router.push({
              path: `/receivableDetail/${res.data.fid}`
            })
            this.isdanjuDialog = false
          } else {
            this.$confirm(res.message, '提示', {
              confirmButtonText: '确定',
              type: 'error'
            })
          }
        })
      }
    }
  }
}
</script>
<style scoped lang="scss">
.outBankEdit {
  @include listBom;
  .tabs{
    &::v-deep .el-tabs__content {
      min-height: calc(100vh - 200px);
      overflow-y: auto;
    }
  }
  .tabPosit {
    padding: 5px;
    box-shadow: 0 0 2px #aaa;
    position: absolute;
    top: 3.8vh;
    left: 0;
    background-color: rgba(255, 255, 255, 1);
    z-index: 99999!important;
  }
  .tabPosit1 {
    padding: 5px;
    box-shadow: 0 0 2px #aaa;
    position: absolute;
    top: -25.69vh;
    left:0;
    background-color: rgba(255, 255, 255, 1);
    z-index: 9999;
  }
  .el-tabs {
    &::v-deep.el-tabs__header {
      margin: 0 0 5px;
    }
    .el-input::v-deep .el-input__inner {
      height: 30px;
      line-height: 30px;
    }
    .el-form {
      display: flex;
      flex-wrap: wrap;

      .el-form-item {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        height: 35px;
        width: 275px;
        margin-bottom: 3px;
        .btnType{
          margin-right: 20px;
        }
        .el-date-editor.el-input{
          width: 100% !important;
        }
        .el-select{
          width: 100%;
        }
      }
    }
  }
}

.el-input__icon {
  cursor: pointer;
}

</style>
